<template>
  <div class="service-wrapper">
    <div class="title">你好，欢迎使用南邮智能客服~</div>
    <div class="tips">
      <div class="left-tip">
        猜你想问（点击弹幕查看回答）
      </div>
      <div class="right-btn">
        <el-icon><Refresh /></el-icon>
        换一批
      </div>
    </div>
    <div class="container">
      <span v-for="(item, index) in list" :style="getStyle(index)"
            :key="item.id" class="card"
            @click="addChatList(item)"
      >
        {{item.content}}
      </span>
    </div>

    <div class="other">
      <span>以上没有想问的？</span>
      <span>发起自定义提问</span>
    </div>
  </div>

</template>
<script setup>
import { defaultQuestions} from "@/views/AI/data";
import { Refresh } from '@element-plus/icons-vue'
import {ref,reactive} from "vue";
import {getUuid,getTimeByHHMMSS,getTimeByHHMM} from "@/utils/util";
const emit = defineEmits(['addChatItem']);

const list = ref([])
list.value= defaultQuestions

// 随机生成每个元素的左侧间距
const getStyle = (index) => {
  // 每两项一个一组，确保每行的第一个元素有随机的 margin-left
  if (index % 2 === 0) {
    // 生成一个0到50px之间的随机值
    const randomMargin = Math.floor(Math.random() * 50) + 'px';
    return { 'margin-left': randomMargin };
  }
  return {};
};

const addChatList=(item)=>{
  const uuid = getUuid();
  let chatQuestionObj = {
    dateTime:getTimeByHHMMSS(),
    isMy:true,
    text:item.content,
  }
  let html=`
    <div>
      <p>你好！我是你的专属AI伙伴，我拥有独特能力</p>
      <p>我非常希望你能给我持续的反馈，帮助我不断成长，期待你与我一起探索未来~</p>
    </div>
  `
  let chatAnswer={
    dateTime:getTimeByHHMMSS(),
    isMy:false,
    text:html,
  }
  let historyList = [chatQuestionObj,chatAnswer]

  let obj ={
    ...item,
    id:uuid,
    history:historyList,
    time:getTimeByHHMM(),
  }

  emit("addChatItem", obj);

};

</script>
<style scoped lang="less">
.service-wrapper{
  padding: 30px 28px;
  .title{
    font-size: 24px;
    color: #3F4040;
    margin-bottom: 30px;
  }

  .tips{
    width: 100%;
    font-size: 18px;
    color: #9AA1B2;

    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 37px;

    .right-btn{
      cursor: pointer;
    }
  }

  .other{
    text-shadow: 0px 6px 4px rgba(41,109,241,0.29);
    font-size: 18px;
    color: #3285FA;
    padding-top: 100px;
    text-align: center;
    span{
      &:first-child{
        color: #747B8B !important;
      }
    }
  }

}

.container {
  display: flex;
  flex-wrap: wrap; /* 允许换行 */
  gap: 20px 80px; /* 设置每个元素之间的间距 */
}

.card {
  display: inline-block;
  background: linear-gradient( 117deg, rgba(171, 167, 254, 0.3) 0%, rgba(66, 204, 225, 0.3) 100%);
  padding:19px 20px;
  font-size: 18px;
  color: #213F99;
  border-radius: 16px 0 16px 0;
  box-sizing: border-box; /* 确保 padding 和边框不影响宽度计算 */
  cursor: pointer;
}

</style>